package com.all.play.mypsm.base;

import android.content.Context;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

/**
 * Created by 聪明一只哈 on 2018/3/31.
 * 首页：HomeFragment

 分类：TypeFragment

 发现：CommunityFragment

 购物车：ShoppingCartFragment

 用户中心：UserFragemnt
 */

public abstract class BaseFragment extends Fragment {

    protected Context mContext;

    /**
     *该类被系统创建
     *@author 聪明一只哈
     *@time 2018/3/31 9:38
     */
    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        mContext=getActivity();
    }

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {

        return initView();
    }

    /**
     *子类实现,加载不同的布局
     *@author 聪明一只哈
     *@time 2018/3/31 9:40
     */
    public abstract View initView();


    /**
     *当activity被创建的时候,回调这个方法,此方法晚于onCreateView,调用
     *@author 聪明一只哈
     *@time 2018/3/31 9:41
     */
    @Override
    public void onActivityCreated(@Nullable Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        initData();
    }

    /**
     *当子类需要请求数据,可重写该方法
     *@author 聪明一只哈
     *@time 2018/3/31 9:42
     */
    public void initData(){

    }
}
